# Maintainer: Jami Kettunen <jami.kettunen@protonmail.com>
# Stable Linux kernel with patches for MSM8998 devices
# Kernel config based on: msm8998_defconfig
_flavor="postmarketos-qcom-msm8998"
pkgname=linux-$_flavor
pkgver=6.0
pkgrel=2
_commit="90169e6e9fee29fae14aeac0a905246be5ce6304"
pkgdesc="Mainline Kernel fork for MSM8998 devices"
arch="aarch64"
_carch="arm64"
_config="config-$_flavor.$arch"
url="https://gitlab.com/msm8998-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
"
makedepends="
	bash
	bison
	findutils
	flex
	linux-headers
	openssl-dev
	perl
	postmarketos-installkernel
	xz
"

# Source
source="
	https://gitlab.com/msm8998-mainline/linux/-/archive/$_commit/linux-$_commit.tar.gz
	$_config
"
builddir="$srcdir/linux-$_commit"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$arch" .config
}

build() {
	unset LDFLAGS
	# V=1: workaround for pma#1990, remove after upgrading to >= 6.2
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1))-$_flavor" V=1
}

package() {
	mkdir -p "$pkgdir"/boot

	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
e1d75369d58f823da5fe0cde17314a4ec2dc9dbab57452b7b8af6b97e91797720162e78f9ca7da2cbb533833b38be86743b8bf0084af1b36b5d23c9207a5248e  linux-90169e6e9fee29fae14aeac0a905246be5ce6304.tar.gz
ec0d124bf92418499a97f9557a76d4343a513e1689e473399c1a12f75a0eb8040af539f2b0edb6ab1151284e488ba4b50c4263bcfad142e4bd68dddd47cc8fce  config-postmarketos-qcom-msm8998.aarch64
"
